<?php
namespace App\Http\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\DB;

class Train extends Model
{
    protected $table = 'ttrain';


    public static function doJoin($input = array())
    {

       return TrainOrder::createOrder($input);


    }

    public static function getList($input = array())
    {
        $entries = self::where('TEndAt', '>=', date('Y-m-d', time()))->orderBy('created_at', 'desc');

        if(isset($input['my']))
        {
            $customer_id=Session::get(User::$session_key);

            $arr=DB::table('ttrainbook')->where('TBCustomerID',$customer_id)->lists('TBTrainID');

            $arr=array_unique($arr);

            $entries=$entries->whereIn('TID',$arr);
        }
        if(isset($input['TType'])){
            $entries=$entries->where('TType',$input['TType']);
        }

        $entries=$entries->paginate(5);

        return $entries;
    }
    //获取某个培训的用户列表
    public static  function getJoinList($input=array())
    {
        $input = array_only($input, array('TBCustomerID','TBTrainID'));

        return DB::table('ttrainbook')->where($input)->first();
    }

}